from songmanager import SongManager , Part
import instruments
from timings import StandardTiming , BehindTheBeat , BangOn
from velocities  import StandardVelocity
import random

class VD( instruments.SequenceInstrument ):
    def __init__(self , sequence ):
        instruments.SequenceInstrument.__init__(self , sequence )
    def getDuration( self ):
        return random.gauss( 0.2 , 0.1 )

s = SongManager()
s.setBPM( 120 )
s.definePattern( "rest" , "-" )
s.definePattern(  "BD1" , "X---")
s.definePattern(  "SD1" , "X-x-x-")

s.definePattern( "HH1" , "--x-x-x-" )
s.definePattern( "OH1" , "X-------" )
s.definePattern( "HH2" , "--x-x-x-x---x-x-x-x-x-x-|----x-x-x-x---x-x-x-x-x-" )
s.definePattern( "OH2" , "x----------x------------|x-----------------------" )
s.defineInstrument( "BD" ,  instruments.GMDrumInstrument( "Bass Drum" ) , BangOn(  ) , StandardVelocity( 120 , 80 , 10 ) )
s.defineInstrument( "FT" ,  instruments.GMDrumInstrument( "Low Tom" ) , BangOn(  ) , StandardVelocity( 120 , 80 , 10 ) )
s.defineInstrument( "T1" ,  instruments.GMDrumInstrument( "Low Mid Tom" ) , BangOn(  ) , StandardVelocity( 120 , 80 , 10 ) )
s.defineInstrument( "T2" ,  instruments.GMDrumInstrument( "Hi Mid Tom" ) , BangOn(  ) , StandardVelocity( 120 , 80 , 10 ) )
s.defineInstrument( "SD" ,  instruments.GMDrumInstrument( "Electric Snare" ) , BehindTheBeat( normal=0.01 , deviation=0.001 ) ,StandardVelocity( 120 , 80 , 20 ) )
s.defineInstrument( "HH" ,  instruments.GMDrumInstrument( "Closed Hi Hat" ) ,  StandardTiming( normal=0.005 , deviation=0.001 ) ,  StandardVelocity( 110 , 60 , 10 ))

s.defineInstrument( "OH" ,  instruments.GMDrumInstrument( "Open Hi Hat" ) ,  StandardTiming( normal=0.005 , deviation=0.001 ) ,  StandardVelocity( 110 , 60 , 10 ))
s.defineTrack( "drums" , 3 )

intro = Part() 
intro["BD"].addPattern( "BD1" ,9 )
intro["T2"].addPattern( "SD1" ,9 )
intro["HH"].addPattern( "HH1" , 4 )
intro["OH"].addPattern( "OH1" , 4 )
intro["HH"].addPattern( "HH2" , 5 )
intro["OH"].addPattern( "OH2" , 5 )

base = Part() 
base["BD"].addPattern( "BD1" ,8 )
base["T2"].addPattern( "SD1" , 8)
base["HH"].addPattern( "rest" , 1 )
base["HH"].addPattern( "HH1" , 2 )
base["OH"].addPattern( "OH1" , 3 )
base["HH"].addPattern( "HH2" , 5 )
base["OH"].addPattern( "OH1" , 5 )






s.defineInstrument( "bass"  , VD( [ "d3" , "g3" ] ) , BehindTheBeat( normal=0.01 , deviation=0.001 ) ,StandardVelocity( 120 , 90 , 10 ) )
s.definePattern( "bass-a" , "Xxxxxxxxxxxx" )
s.defineTrack( "bass" , 4 )



p3=Part()
p3["bass"].addPattern( "bass-a" , 3 * 8 + 9 )

s["drums"].addPart( intro )
s["drums"].addPart( base , 3 )

s["bass"].addPart( p3 )
s.run()
